package com.orange.modules.dao;

import java.sql.SQLException;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.school_data.AuthResourceData;

@Repository
public class AuthResourceDataRepository {
	
	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthResourceDataDao authResourceDataDao;
	
	
	public void insertAuthResourceData(AuthResourceData ard) throws SQLException{
		authResourceDataDao.save(ard);
	}
	
	
	public AuthResourceData queryAuthResourceDataBySchoolId(String schoolId,String loginType) throws SQLException{
		String sql = "SELECT t.p_id as pid,t.s_total_library_collection as totalLibraryCollection,"
				+ "t.s_electronic_books as electronicBooks,t.s_related_professional_books as relatedProfessionalBooks,"
				+ "t.s_student_related_professional_books as studentRelatedProfessionalBooks,t.s_recommended_book as recommendedBook,"
				+ "t.s_average_annual_book as averageAnnualBook,t.s_readingroom_journals as readingroomJournals,"
				+ "t.s_students_free_reading as studentsFreeReading,t.s_students_digital_resources as studentsDigitalResources,"
				+ "t.s_professional_journals as professionalJournals,t.s_skills_training_room_area as skillsTrainingRoomArea,"
				+ "t.s_shared_area as sharedArea,t.s_skills_training_room_types as skillsTrainingRoomTypes,"
				+ "t.s_shared_room as sharedRoom,t.s_equipment_cost as equipmentCost,t.s_shared_device_value as sharedDeviceValue,"
				+ "t.s_createtime as createtime,t.s_id as sid,t.login_type as loginType,t.s_status as status, t.s_remark as remark FROM t_auth_resource_data 	t WHERE t.s_id =?";
		if(StringUtils.isNotBlank(loginType)){
			sql+="AND  t.login_type ='"+loginType+"'";
		}
		AuthResourceData ard = dbHelper.getBean(sql, AuthResourceData.class,schoolId);
		return ard;
	}

}
